package com.llcbenwu.exception;

import com.llcbenwu.config.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author lilinchun
 * @date 2021/10/21 0021 16:52
 */
@ControllerAdvice
public class BusinessExceptionHandler {

    //指定出现什么异常执行这个方法
    @ExceptionHandler(BusinessException.class)
    @ResponseBody  //返回数据
    public Result error(BusinessException e){
        e.printStackTrace();
        return new Result(e.getCode(),e.getMsg());
    }

}
